home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / RectShp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.6 KB  |  292 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RectShp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef RECTSHP_H
  23. #include "RectShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWGRUTIL_H
  79. #include "FWGrUtil.h"
  80. #endif
  81.  
  82. #ifndef FWEVENT_H
  83. #include "FWEvent.h"
  84. #endif
  85.  
  86. #ifndef FWRECSHP_H
  87. #include "FWRecShp.h"
  88. #endif
  89.  
  90. #ifndef FWTXTBOX_H
  91. #include "FWTxtBox.h"
  92. #endif
  93.  
  94. #ifndef FWLINSHP_H
  95. #include "FWLinShp.h"
  96. #endif
  97.  
  98. #ifndef FWOVLSHP_H
  99. #include "FWOvlShp.h"
  100. #endif
  101.  
  102. #ifndef FWRRCSHP_H
  103. #include "FWRRcShp.h"
  104. #endif
  105.  
  106. #ifndef FWODGEOM_H
  107. #include "FWODGeom.h"
  108. #endif
  109.  
  110. // ----- Foundation Includes -----
  111.  
  112. #ifndef FWSTREAM_H
  113. #include "FWStream.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_ODTransform_xh
  119. #include <Trnsform.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfdrawshapes
  128. #endif
  129.  
  130. //========================================================================================
  131. // RunTime Info
  132. //========================================================================================
  133.  
  134. FW_DEFINE_AUTO(CRectShape)
  135. FW_DEFINE_CLASS_M1(CRectShape, CBoundedShape)
  136.  
  137. const FW_ClassTypeConstant LRectShape = FW_TYPE_CONSTANT('s','h','r','c');
  138. FW_REGISTER_ARCHIVABLE_CLASS(LRectShape, CRectShape, CRectShape::Read, 0, 0, CBaseShape::Write)
  139.  
  140. //========================================================================================
  141. // class CRectShape
  142. //========================================================================================
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // CRectShape::CRectShape
  146. //----------------------------------------------------------------------------------------
  147.  
  148. CRectShape::CRectShape(CDrawPart* drawPart) :
  149.     CBoundedShape(drawPart, kRectShape, kFrameOnly)
  150. {
  151.     FW_END_CONSTRUCTOR
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // CRectShape::CRectShape
  156. //----------------------------------------------------------------------------------------
  157.  
  158. CRectShape::CRectShape(CDrawPart* drawPart, unsigned short shapeType, unsigned short renderVerb) :
  159.     CBoundedShape(drawPart, shapeType, renderVerb)
  160. {
  161.     FW_END_CONSTRUCTOR
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. // CRectShape::CRectShape
  166. //----------------------------------------------------------------------------------------
  167.  
  168. CRectShape::CRectShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  169.     CBoundedShape(drawPart, archive)
  170. {    
  171.     FW_END_CONSTRUCTOR
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. // CRectShape::~CRectShape
  176. //----------------------------------------------------------------------------------------
  177.  
  178. CRectShape::~CRectShape()
  179. {
  180.     FW_START_DESTRUCTOR
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // CRectShape::RenderShape
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void CRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  188. {
  189. FW_UNUSED(ev);
  190. FW_UNUSED(facet);
  191.     FW_CRect rect = GetRectGeometry();
  192.     AdjustRectForPenSize(rect, GetPenSize());
  193.  
  194.     if (HasFillStyle())
  195.         FW_CRectShape::RenderRect(gc, rect, FW_kFill, fFillInk, fFillStyle);
  196.     
  197.     if (HasFrameStyle())
  198.         FW_CRectShape::RenderRect(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. // CRectShape::HitTest
  203. //----------------------------------------------------------------------------------------
  204.  
  205. FW_Boolean CRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  206. {
  207.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  208.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  209.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  210.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  211.     
  212.     FW_CRect bounds = GetRectGeometry();
  213.     AdjustRectForPenSize(bounds, GetPenSize());
  214.  
  215.     FW_CRectShape rectShape(bounds, HasFillStyle() ? FW_kFill : FW_kFrame);
  216.     return rectShape.HitTest(gc, mouse, FW_IntToFixed(2));
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // CRectShape::OutlineShape
  221. //----------------------------------------------------------------------------------------
  222.  
  223. void CRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  224. {
  225.     FW_CRect bounds(rect);
  226.     AdjustRectForPenSize(bounds, style.GetPenSize());
  227.     FW_CRectShape::RenderRect(gc,
  228.                               bounds,
  229.                               FW_kFrame,
  230.                               ink, style);
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. // CRectShape::CalcClipShape
  235. //----------------------------------------------------------------------------------------
  236.  
  237. ODShape* CRectShape::CalcClipShape(Environment *ev)
  238. {
  239.     FW_CRect bounds = GetRectGeometry();
  240.     AdjustRectForPenSize(bounds, GetPenSize());
  241.     
  242.     FW_CAcquiredODShape clipShape = ::FW_NewODShape(ev, bounds);
  243.     
  244.     if (FrameOnly())
  245.     {
  246.         bounds.Inset(GetPenSize(), GetPenSize());
  247.         
  248.         FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev, bounds);
  249.         clipShape->Subtract(ev, aqTempShape);
  250.     }
  251.     
  252.     return clipShape.Orphan();
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. // CRectShape::CreateShapeOutline
  257. //----------------------------------------------------------------------------------------
  258.  
  259. ODShape* CRectShape::CreateShapeOutline(Environment *ev)
  260. {
  261.     FW_CRect bounds = GetRectGeometry();
  262.     AdjustRectForPenSize(bounds, GetPenSize());
  263.  
  264.         // We don't acquire it because we return it
  265.     ODShape* dragRgn = ::FW_NewODShape(ev, bounds);
  266.  
  267.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  268.  
  269.     return dragRgn;
  270. }
  271.  
  272. //----------------------------------------------------------------------------------------
  273. // CRectShape::Read
  274. //----------------------------------------------------------------------------------------
  275.  
  276. void* CRectShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  277. {
  278. FW_UNUSED(type);
  279.     // [HLX] This is a hack until I can register object with the archiver
  280.     CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
  281.     return FW_NEW(CRectShape, (drawArchive->GetDrawPart(), stream));
  282. }
  283.  
  284. //----------------------------------------------------------------------------------------
  285. // CRectShape::GetObjectClass
  286. //----------------------------------------------------------------------------------------
  287.  
  288. ODDescType CRectShape::GetObjectClass() const
  289. {
  290.     return cRectangle;
  291. }
  292.